package com.cqc.activityoptioncompat01;

import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    private ImageView iv;
    private Button btn;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;
    private Button btn6;
    private Button btn7;
    private Button btn8;
    private Button btn9;
    private Button btn10;
    private Button btn11;
    private Button btn12;
    private Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        context = this;

        iv = (ImageView) findViewById(R.id.iv_main);
        btn = (Button) findViewById(R.id.btn_main);
        btn2 = (Button) findViewById(R.id.btn_main2);
        btn3 = (Button) findViewById(R.id.btn_main3);
        btn4 = (Button) findViewById(R.id.btn_main4);
        btn5 = (Button) findViewById(R.id.btn_main5);
        btn6 = (Button) findViewById(R.id.btn_main6);
        btn7 = (Button) findViewById(R.id.btn_main7);
        btn8 = (Button) findViewById(R.id.btn_main8);
        btn9 = (Button) findViewById(R.id.btn_main9);
        btn10 = (Button) findViewById(R.id.btn_main10);
        btn11 = (Button) findViewById(R.id.btn_main11);
        btn12 = (Button) findViewById(R.id.btn_main12);

        btn.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);
        btn6.setOnClickListener(this);
        btn7.setOnClickListener(this);
        btn8.setOnClickListener(this);
        btn9.setOnClickListener(this);
        btn10.setOnClickListener(this);
        btn11.setOnClickListener(this);
        btn12.setOnClickListener(this);

    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
//                ActivityCompat.finishAfterTransition(MainActivity.this);//直接使用finish()也可以
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_main:
                ActivityOptionsCompat options = ActivityOptionsCompat.makeCustomAnimation(context, android.R.anim.slide_in_left, android.R.anim.slide_out_right);
                ActivityCompat.startActivity(context, new Intent(context, Activity_I.class), options.toBundle());
                break;

            case R.id.btn_main2:
                ActivityOptionsCompat options2 = ActivityOptionsCompat.makeScaleUpAnimation(view, view.getWidth() / 2, view.getHeight() / 2, 1000, 1000);
                ActivityCompat.startActivity(context, new Intent(context, Activity_I.class), options2.toBundle());
                break;
            case R.id.btn_main3://view.getWidth()/2,view.getHeight()/2
                ActivityOptionsCompat options3 = ActivityOptionsCompat.makeThumbnailScaleUpAnimation(view, BitmapFactory.decodeResource(getResources(), R.mipmap.b), 0, 0);
                ActivityCompat.startActivity(context, new Intent(context, Activity_I.class), options3.toBundle());
                break;
            case R.id.btn_main4:
                ActivityOptionsCompat options4 = ActivityOptionsCompat.makeClipRevealAnimation(view, view.getWidth() / 2, view.getHeight() / 2, 1000, 1000);
                ActivityCompat.startActivity(context, new Intent(context, Activity_I.class), options4.toBundle());
                break;
            case R.id.btn_main5:
                ActivityOptionsCompat options5 = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this, iv, "options5");
                ActivityCompat.startActivity(context, new Intent(context, Activity_A.class), options5.toBundle());
                break;
            case R.id.btn_main6:
                ActivityOptionsCompat options6 = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);
                ActivityCompat.startActivity(context, new Intent(context, Activity_B.class), options6.toBundle());
                break;
            case R.id.btn_main7:
                ActivityOptionsCompat options7 = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);
                ActivityCompat.startActivity(context, new Intent(context, Activity_C.class), options7.toBundle());
                break;
            case R.id.btn_main8:
                ActivityOptionsCompat options8 = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);
                ActivityCompat.startActivity(context, new Intent(context, Activity_D.class), options8.toBundle());
                break;
            case R.id.btn_main9:
                ActivityOptionsCompat options9 = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);
                ActivityCompat.startActivity(context, new Intent(context, Activity_E.class), options9.toBundle());
                break;
            case R.id.btn_main10:
                ActivityOptionsCompat options10 = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);
                ActivityCompat.startActivity(context, new Intent(context, Activity_F.class), options10.toBundle());
                break;
            case R.id.btn_main11:
                ActivityOptionsCompat options11 = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);
                ActivityCompat.startActivity(context, new Intent(context, Activity_G.class), options11.toBundle());
                break;
            case R.id.btn_main12:
                ActivityOptionsCompat options12 = ActivityOptionsCompat.makeSceneTransitionAnimation(MainActivity.this);
                ActivityCompat.startActivity(context, new Intent(context, Activity_H.class), options12.toBundle());
                break;
        }
    }
}
